#include "animationhacker.h"
#include "utilsprivate.h"

#include <QDebug>

AnimationHacker::AnimationHacker(QObject *parent):QObject(parent)
{

}

QObject *AnimationHacker::target() const
{
    return m_target;
}

void AnimationHacker::setTarget(QObject *newTarget)
{
    if (m_target == newTarget)
        return;
    m_target = newTarget;
    update();
    emit targetChanged();
}

void AnimationHacker::update()
{
    if(!m_target)
    {
        setResult(NULL);
        return;
    }

    for(auto i : m_target->findChildren<QObject*>())
    {
        if(UtilsPrivate::isBase(QStringLiteral("QQuickTimeline"),i->metaObject()))
        {

            setResult(i);
            return;
        }
    }

    setResult(NULL);
}

QObject *AnimationHacker::result() const
{
    return m_result;
}

void AnimationHacker::setResult(QObject *newResult)
{
    if (m_result == newResult)
        return;
    m_result = newResult;
    emit resultChanged();
}

